import { hasToken } from '@/utils/tokens';
import { Redirect, Route, RouteProps } from 'react-router-dom';
type PrivateRouteProps = RouteProps & {};
export default function PrivateRoute({ children, ...rest }: PrivateRouteProps) {
  return (
    <Route
      {...rest}
      render={({ location }) =>
        hasToken() ? (
          children
        ) : (
          <Redirect
            to={{ pathname: '/login', state: { from: location.pathname } }}
          ></Redirect>
        )
      }
    ></Route>
  );
}
